package com.smartscreen.lifeserviceinfomanage.service.impl;

import com.smartscreen.lifeserviceinfomanage.dto.ShuttleBusScheduleDTO;
import com.smartscreen.lifeserviceinfomanage.entity.ShuttleBusSchedule;
import com.smartscreen.lifeserviceinfomanage.mapper.ShuttleBusScheduleMapper;
import com.smartscreen.lifeserviceinfomanage.service.ShuttleBusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class ShuttleBusServiceImpl implements ShuttleBusService {
    
    @Autowired
    private ShuttleBusScheduleMapper shuttleBusScheduleMapper;
    
    @Override
    public List<ShuttleBusScheduleDTO> getSchedule() {
        List<ShuttleBusSchedule> schedules = shuttleBusScheduleMapper.selectList(null);
        return schedules.stream().map(this::convertToDTO).collect(Collectors.toList());
    }
    
    private ShuttleBusScheduleDTO convertToDTO(ShuttleBusSchedule schedule) {
        ShuttleBusScheduleDTO dto = new ShuttleBusScheduleDTO();
        dto.setRouteName(schedule.getRouteName());
        dto.setWeekdays(Arrays.asList(schedule.getWeekdaySchedule().split(",")));
        dto.setWeekends(Arrays.asList(schedule.getWeekendSchedule().split(",")));
        return dto;
    }
}